package com.xiaomaoguai.redis.string;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import javax.annotation.Resource;

/**
 * @ FileName: StringTestMain.java
 * @ Author: WeiHui-Z
 * @ Date: 2017/6/5 19:40
 * @ Version: v1.0.0
 * @see org.springframework.data.redis.core.ValueOperations
 */
@ContextConfiguration(locations = {"classpath:spring-redis.xml"})
public class StringTestMain extends AbstractJUnit4SpringContextTests {

    private static final Logger LOGGER = LoggerFactory.getLogger(StringTestMain.class);

    @Resource(name = "redisTemplate")
    private ValueOperations<String, String> valueOperations;

    @Test
    public void testSet() {
        valueOperations.set("TEST", "hello redis pub");
    }

    @Test
    public void testSetNx() {
        LOGGER.info("加锁成功： {}", valueOperations.setIfAbsent("lock", "locker"));
    }

    @Test
    public void testGetSet() {
        LOGGER.info("上次数据： {}", valueOperations.getAndSet("Num", "old"));
    }

}
